#include "includeme.h"
#include "generated/task.h"

int __semwait_signal(int cond_sem, int mutex_sem, int timeout, int relative, int64_t tv_sec, int32_t tv_nsec);

semaphore_t clock_sem = 0;

int nanosleep(int64_t tv_sec, int32_t tv_nsec)
{
	if (clock_sem == 0) {
		semaphore_create(mach_task_self_, (semaphore_t *)&clock_sem, 0, 0);
	}
	return __semwait_signal(clock_sem, 0, 1, 1, tv_sec, tv_nsec);
}


int usleep(uint64_t useconds)
{
	return nanosleep(useconds / 1000000, 1000 * (useconds % 1000000));
}
